﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

namespace BSCMFF.Web.Pages.Evaluation_Setup
{
    public partial class EvaluationForm : BSCMFF.Core.MultiLanguagePage
    {
        private int currentNumberOfQuestions;
        private static bool create = true;

        protected void Page_Load(object sender, EventArgs e)
        {

            //if (IsPostBack && ((Button)sender).ID == "bp")
            //{
            //    ButtonCreateQuestions_Click(sender, e);
            //}
            if (IsPostBack && PanelQuestions.Controls.Count == 1)
            {
                create = true;
                ButtonCreateQuestions_Click(sender, e);
            }
        }

        protected void ButtonCreateQuestions_Click(object sender, EventArgs e)
        {
            if (create)
            {

                currentNumberOfQuestions = (int)RadNumericTextBoxNumberOfQuestions.Value;

                for (int i = 0; i < RadNumericTextBoxNumberOfQuestions.Value; ++i)
                {
                    RadTextBox q = new RadTextBox();

                    q.ID = "Question" + i.ToString();
                    q.Width = 500;

                    PanelQuestions.Controls.Add(q);

                    PanelQuestions.Controls.Add(new LiteralControl("<span>"));

                    for (int j = (int)RadNumericTextBoxMin.Value; j <= (int)RadNumericTextBoxMax.Value; ++j)
                    {
                        RadioButton rb = new RadioButton();

                        string si = i < 10 ? "0" + i.ToString() : i.ToString();
                        string sj = j < 10 ? "0" + j.ToString() : j.ToString();

                        rb.ID = "Radio" + si + sj;
                        rb.GroupName = "Group" + i.ToString();
                        PanelQuestions.Controls.Add(rb);
                    }

                    PanelQuestions.Controls.Add(new LiteralControl("</span>"));
                    //PlaceHolder ph = new PlaceHolder();

                    //ph.ID = "PlaceHolder" + i.ToString();

                    //PanelQuestions.Controls.Add(ph);

                    PanelQuestions.Controls.Add(new LiteralControl("<br />"));

                }
            }
            create = false;
        }


        protected void bp_Click(object sender, EventArgs e)
        {
            //ButtonCreateQuestions_Click(sender, e);
            create = true;
        }
    }
}